var util = require('../../utils/util')
Page({
  data: {},

  previewImg(e) {
    // console.log(e.currentTarget.dataset.index)
    let index = e.currentTarget.dataset.index;
    wx.previewImage({
      current: this.data.imgArr[index],
      urls: this.data.imgArr,
    })
  },
  getShopInfo() {
    let shop_id = getApp().globalData.enterShopInfo.shop_id;
    let data = {
      shop_id,
    }
    util.sendRequest('shop/detail', 'GET', data).then(res => {
      // console.log(res)
      if (res.data.code === 0) {
        let result = res.data.result;
        //将door_head_img，storefront_img，cook_img 字符串转换成一个数组
        let imgStr = (result.door_head_img + ',' + result.storefront_img + ',' + result.cook_img).replace(/,null|null,/g, "")
        let arr = imgStr.split(',');
        let urls = getApp().globalData.urls
        for (let i in arr) {
          arr[i] = urls + arr[i]
        }
        // console.log(imgStr)
        // console.log(arr)
        this.setData({
          shopInfo: result,
          imgArr: arr
        })
      }
    })

  },

  onLoad: function (options) {
    this.setData({
      urls: getApp().globalData.urls
    })
    this.getShopInfo()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})